package com.imooc.ecommerce.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置登录请求转发规则
 *
 * @author zhangshao
 * @date 2023/11/25 10:48
 */
@Configuration
public class RouteLocatorConfig {

    /**
     * 使用代码去定义路由规则,在网关层面拦截登录和注册接口
     *
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator loginRouteLocator(RouteLocatorBuilder builder) {

        //手动定义 Gateway路由规则需要指定 id、path和uri
        return builder.routes().route("e_commerce_authority",
                r -> r.path(
                        "/imooc/e-commerce/login",
                "/imooc/e-commerce/register"
                ).uri("http://localhost:9000/")
        ).build();
    }
}
